package com.ruoyi.web.controller.system;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.BFile_af;
import com.ruoyi.system.service.IBFile_afService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 电子文件Controller
 *
 * @author guangpipi
 * @date 2023-09-21
 */
@RestController
@RequestMapping("/system/efile")
public class BFile_afController extends BaseController
{
    @Autowired
    private IBFile_afService bEFileService;

    /**
     * 查询电子文件列表
     */
//    //@PreAuthorize("@ss.hasPermi('system:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(BFile_af bEFile)
    {
        startPage();
        PageHelper.orderBy("wenJianName");
        List<BFile_af> list = bEFileService.selectBEFileList(bEFile);
        return getDataTable(list);
    }

    /**
     * 导出电子文件列表
     */
//    //@PreAuthorize("@ss.hasPermi('system:file:export')")
    @Log(title = "电子文件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BFile_af bEFile)
    {
        List<BFile_af> list = bEFileService.selectBEFileList(bEFile);
        ExcelUtil<BFile_af> util = new ExcelUtil<BFile_af>(BFile_af.class);
        util.exportExcel(response, list, "电子文件数据");
    }

    /**
     * 获取电子文件详细信息
     */
//    //@PreAuthorize("@ss.hasPermi('system:file:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(bEFileService.selectBEFileById(id));
    }

    /**
     * 新增电子文件
     */
//    //@PreAuthorize("@ss.hasPermi('system:file:add')")
    @Log(title = "电子文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BFile_af bEFile)
    {
        return toAjax(bEFileService.insertBEFile(bEFile));
    }

    /**
     * 修改电子文件
     */
//    //@PreAuthorize("@ss.hasPermi('system:file:edit')")
    @Log(title = "电子文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BFile_af bEFile)
    {
        return toAjax(bEFileService.updateBEFile(bEFile));
    }

    /**
     * 删除电子文件
     */
//    //@PreAuthorize("@ss.hasPermi('system:file:remove')")
    @Log(title = "电子文件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(bEFileService.deleteBEFileByIds(ids));
    }
}
